const INFO_KEY = 'hrw_shopping_info'
const HISTORY_KEY = 'hrw_history_list'

// 获取用户个人信息
const getInfo = () => {
  const result = localStorage.getItem(INFO_KEY)
  return result ? JSON.parse(result) : { token: '', userId: '' }
}
// 设置用户个人信息
const setInfo = (info) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(info))
}
// 删除用户个人信息
const removeInfo = () => {
  localStorage.removeItem(INFO_KEY)
}
// 获取搜索历史
const getHistoryList = () => {
  const result = localStorage.getItem(HISTORY_KEY)
  return result ? JSON.parse(result) : []
}
// 设置搜索历史
const setHistoryList = (arr) => {
  localStorage.setItem(HISTORY_KEY, JSON.stringify(arr))
}
// 作用：对用户信息做本地化存储
export {
  getInfo,
  setInfo,
  removeInfo,
  getHistoryList,
  setHistoryList
}
